package com.zoweunion.mechanic.config;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "rabbitmq-for-login")
public class RabbitMQForLoginConfig {
    private String addresses;
    private String userName;
    private String passWord;
    private String virtualHost;
    public void setAddresses(String addresses) {
        this.addresses = addresses;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public void setPassWord(String passWord) {
        this.passWord = passWord;
    }
    public void setVirtualHost(String virtualHost) {
        this.virtualHost = virtualHost;
    }

    public RabbitTemplate rabbitTemplateForLogin() {
        CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory();
        cachingConnectionFactory.setAddresses(this.addresses);
        cachingConnectionFactory.setUsername(this.userName);
        cachingConnectionFactory.setPassword(this.passWord);
        cachingConnectionFactory.setVirtualHost(this.virtualHost);

        return new RabbitTemplate(cachingConnectionFactory);
    }
}